//
//  FPLoanModel.m
//  FinanceProject
//
//  Created by 陈显摆 on 2025/2/7.
//

#import "FPLoanModel.h"

@implementation FPLoanModel


+ (void)checkLoanContractInfoWithParam:(NSString *)paramString success:(void (^)(NSInteger code , NSString *message))success failure:(void (^)(NSError *error))failure {
    
//    NSMutableDictionary *param = APIClient.creatAPIDictionary;
//    
//#warning paramString
//    [param setObject:paramString forKey:@"paramString"];
//    
//    NSString *URLString = [APIClient getQueryURLStringWithParam:param URLString:CHECK_INFO_SAVE_TEMP_URL];
//    
//    [[APIClient sharedInstance] requestWithURLString:[MAIN_URL stringByAppendingString:URLString] parameters:@{} type:HttpRequestTypeGet success:^(id responseObject, NSString *msg, NSInteger code) {
//        
//        NSError *error;
//        
//        id object = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:&error];
//        
//        NSInteger httpCode = [[object objectForKey:@"code"] integerValue];
//        
//        NSString *message = [object objectForKey:@"msg"];
//        
//        if (success) {
//            
//            success(httpCode , message);
//        }
//        
//    } failure:^(NSError *error) {
//        
//        if (failure) {
//            failure(error);
//        }
//    }];
}



+ (void)saveLoanContractInfoWithParam:(FPLoanModel *)param timeStamp:(long long)timeStamp success:(void (^)(NSInteger code , NSString *message))success failure:(void (^)(NSError *error))failure {
    
    NSDictionary *params = [param toDictionary];
    
    NSMutableDictionary *temp = NSMutableDictionary.dictionary;
    
    [temp setObject:[NSString stringWithFormat:@"loanContract%lld", timeStamp] forKey:@"key"];
    [temp setObject:params forKey:@"value"];
    
    [[APIClient sharedInstance] requestWithURLString:[MAIN_URL stringByAppendingString:CONTRACT_INFO_SAVE_TEMP_URL] parameters:temp type:HttpRequestTypePost success:^(id responseObject, NSString *msg, NSInteger code) {
        
        NSError *error;
        
        id object = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:&error];
        
        NSInteger httpCode = [[object objectForKey:@"code"] integerValue];
        
        NSString *message = [object objectForKey:@"msg"];
        
        if (success) {
            
            success(httpCode , message);
        }
        
    } failure:^(NSError *error) {
        
        if (failure) {
            failure(error);
        }
    }];
}

+ (void)submitLoanWithParam:(NSDictionary *)param success:(void (^)(NSInteger, NSString * _Nonnull))success failure:(void (^)(NSError * _Nonnull))failure {
    
    [[APIClient sharedInstance] requestWithURLString:[MAIN_URL stringByAppendingString:LOAN_ADD_URL] parameters:param type:HttpRequestTypePost success:^(id responseObject, NSString *msg, NSInteger code) {
        
        NSError *error;
        
        id object = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:&error];
        
        NSInteger httpCode = [[object objectForKey:@"code"] integerValue];
        
        NSString *message = [object objectForKey:@"msg"];
        
        if (success) {
            
            success(httpCode , message);
        }
        
    } failure:^(NSError *error) {
        
        if (failure) {
            failure(error);
        }
    }];
}

@end
